#include "types.h"
#include "vm.h"
#include "pmm.h"
#include "kalloc.h"
#include "assert.h"
#include "test_vm.h"
void test_pagetable() {
    pagetable_t pt = create_pagetable();
    assert(pt != NULL);  // 检查页表创建成功

    uint64 pa = (uint64)kalloc();
    uint64 va = 0x200000;
    
    // 使用正确的函数名
    assert(map_page(pt, va, pa, PTE_R | PTE_W) == 0);
    
    // 使用walk_lookup而非walk
    pte_t *pte = walk_lookup(pt, va);
    assert(pte != NULL);
    assert(*pte & PTE_V);
    
    free_pagetable(pt);
}

void test_virtual_memory() {
    printf("=== Virtual Memory Test ===\n");
    
    // 启用分页前分配内存
    void *page = kalloc();
assert(page != NULL);
uint64 *ptr = page;
    *ptr = 0x12345678;
    
    // 启用分页
    kvminit();
    kvminithart();
    
    // 验证分页后访问
    assert(*ptr == 0x12345678);
    printf("Virtual access verified\n");
}
